package org.come.control;

import org.come.action.FromServerAction;
import org.come.bean.*;
import org.come.entity.Goodstable;
import org.come.until.GoodsListFromServerUntil;
import org.come.until.GsonUtil;
import org.come.until.UserMessUntil;

import java.util.concurrent.ConcurrentHashMap;

public class AutoTaskControl implements FromServerAction {
    public void controlMessFromServer(String mes, String type) {
        if (mes.startsWith("GETLIMIT")) {
            String[] result = mes.split("\\|");
            if (result[1] != null) {
                AutoActiveReidsBase sa = GsonUtil.getGsonUtil().getgson().fromJson(result[1], AutoActiveReidsBase.class);
                UserMessUntil.addAlltutoactive(sa);
            }
        }else if(mes.startsWith("GETCOMNUM")){
            String[] result = mes.split("\\|");
            if (result[1] != null) {
                AutoActiveRedisBaseBean sa = GsonUtil.getGsonUtil().getgson().fromJson(result[1], AutoActiveRedisBaseBean.class);
                UserMessUntil.setAutoActiveRedisBaseBean(sa);
                if(UserMessUntil.getAllAutoActive()!=null && sa.getAllautobase()!=null && sa.getAllautobase().size()>0){
                    for(AutoActiveReidsBase autoActiveReidsBase :sa.getAllautobase()){
                        for(AutoActiveBase autoActiveBase:UserMessUntil.getAllAutoActive().getAllautobase()){
                            if(autoActiveReidsBase.getId() == autoActiveBase.getId()){
                                autoActiveBase.setComNum(autoActiveReidsBase.getComNum());
                            }
                        }
                    }
                }
            }
        }
    }
}
